Option Explicit

Dim doc
Set doc = application.ActiveDocument
main
sub main()
	If ValidateServer(doc) = 0 Then
	    msgbox "Server validation failed."
	    exit sub
	End If
		Dim LayerCountNum,isTpads,isBpads,isTsd,isBsd,activeLayer
	LayerCountNum=doc.LayerCount
	'application.Gui.display LayerCountNum
	'isTpads = doc.ActiveView.DisplayControl.ConductorLayer(1,EpcbDCPads)
	isTsd = doc.ActiveView.DisplayControl.GeneralItems (epcbDCSolderpasteTop)
	activeLayer= application.gui.ActiveRouteLayer

	if (activeLayer="1") Then
	
		if ( isTsd=False ) Then
			'application.Gui.display "false"
			isTsd = not isTsd
			doc.ActiveView.DisplayControl.GeneralItems (epcbDCSolderpasteTop)= isTsd
		else 
			isTsd = not isTsd
			doc.ActiveView.DisplayControl.GeneralItems (epcbDCSolderpasteTop)= isTsd
		end if

	end if
	
	'isBpads = doc.ActiveView.DisplayControl.ConductorLayer(LayerCountNum,EpcbDCPads)
	isBsd = doc.ActiveView.DisplayControl.GeneralItems (epcbDCSolderpasteBottom )
	if (activeLayer=LayerCountNum) Then
	
		if ( isBsd=False ) Then
		'application.Gui.display "false"
		isBsd = not isBsd
		doc.ActiveView.DisplayControl.GeneralItems (epcbDCSolderpasteBottom )= isBsd
		
		else 
			'application.Gui.display "True"
			isBsd = not isBsd
			doc.ActiveView.DisplayControl.GeneralItems (epcbDCSolderpasteBottom )= isBsd
		end if
	end if	
	if (activeLayer<>"1" AND activeLayer<>LayerCountNum) Then
		'application.Gui.display "haha"
		doc.ActiveView.DisplayControl.GeneralItems (epcbDCSolderpasteBottom )= False
		doc.ActiveView.DisplayControl.GeneralItems (epcbDCSolderpasteTop)=False
	end if
end sub

' Function to validate document
Private Function ValidateServer(docObj)
    Dim key, licenseServer, licenseToken
    key = docObj.Validate(0)
    Set licenseServer = CreateObject("MGCPCBAutomationLicensing.Application")
    licenseToken = licenseServer.GetToken(key)
    Set licenseServer = nothing
    'On Error Resume Next
    Err.Clear
    docObj.Validate(licenseToken)
    If Err Then
        ValidateServer = 0    
    Else 
        ValidateServer = 1
    End If
End Function

